package enemies;
/*
 * It's basically a class for easy enemies which fires no missile
 * other stronger enemies extend this class
 */


import game.FlyingObj;

import javax.swing.*;
import java.awt.image.*;

public class BasicEnemy extends FlyingObj implements game.Constants
{
	public int maxHP = 4;
    public int damageHitPlayer; //the amount of damage inflicted upon player if there is a collision
    public double dropRate;

    public BasicEnemy(int x, int y)
    {
    	this.x = x;
        this.y = y + height;
        damageHitPlayer = 2;
        speed = 1;
        hp = maxHP;
        dropRate = 0.2;
        setImage(BASIC_ENEMY);
    }
    
    public BasicEnemy(int x) //initial x-coordinate, and y = 0
    {
        this(x, 0);
    }
    
    public void act() {
        this.y += speed;
        if (getY() >= MAIN_HEIGHT) die();
    }
    
    public void beingHit(int damage)
    {  	
    	hp -= damage;    
    	if (hp <= 0) die();
    	else if (hp < maxHP / 2) 
    	{
    		JFrame j = new JFrame();
    		ImageFilter colorFilter = new RedBlueSwapFilter();
            setImage(j.createImage(new FilteredImageSource(getImage().getSource(), colorFilter)));
    	}
    }
    
    protected class RedBlueSwapFilter extends RGBImageFilter {
        public RedBlueSwapFilter() {
            // The filter's operation does not depend on the
            // pixel's location, so IndexColorModels can be
            // filtered directly.
            canFilterIndexColorModel = true;
        }

        public int filterRGB(int x, int y, int rgb) {
            return ((rgb & 0xffffffff)
                    | ((rgb & 0xff0000) >> 16)
                    | ((rgb & 0xff) << 16));
        }
    }
}